package org.sgsm.dungeon.generator.method;

import org.sgsm.dungeon.generator.ObjectType;

public class MethodDelete extends MethodCRUD
{
  public MethodDelete()
  {
  }

  public void generateServiceImpl()
  {
    print(getSignature());
    up();
    print("if( p" + getBean() + " != null)");
    up();
    print("Session session = getSession();");
    print(getBean() + " result =  (" + getBean() + ") session.get(" + getBean() + ".class, p" + getBean() + ".getId());");
    print("if( result != null)");
    up();
    print("Transaction tx = session.beginTransaction();");
    print("session.delete(result);");
    print("tx.commit();");
    down();
    print("session.close();");
    down();
    down();
  }

  public void generateName(String pPack, String pName)
  {
    _ObjetOut = new ObjectType("", "void");
    _ObjetIn.add(new ObjectType(pPack, pName + "KeyType"));
    _ObjetIn.add(new ObjectType(pPack, pName + "ScenarioType"));
    _ObjetIn.add(getContext());
    setMethodName("delete" + pName);
  }
}
